<template>
  <a-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
     <!--  开始时间 
 <a-date-picker v-model="starttime"  :format="dateFormat" @change="this.getpeopleList" />
   结束时间
  <a-date-picker v-model="endtime"   :format="dateFormat"  @change="this.getpeopleList"/> -->
    <a-input placeholder="客户名称"  style="width:150px" v-model="companyName" @blur="this.getpeopleList"></a-input>
	
	   <a-input placeholder="客户编号"  style="width:150px" v-model="companyCode" @blur="this.getpeopleList"></a-input>
	
 <a-table 
 
 :columns="columns"
  :data-source="data"
    :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  :pagination="ipagination"  
	   @change="handleTableChange">
    <template #name="{text}">
      <a>{{ text }}</a>
    </template>
  </a-table>


  
  </a-modal>
</template>

<script>
const columns = [
  {
    title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
  },
  {
    title: '客户名称',
    dataIndex: 'companyName',
  
    width: 80,
  },
  {
    title: '客户编号',
    dataIndex: 'companyCode',
   
    width: 80,
  },
  {
    title: '联系电话',
    dataIndex: 'phone',
   
    ellipsis: true,
  },
	{
	  title: '当前折扣体系',
	  dataIndex: 'discountSystemName',
	
	  ellipsis: true,
	},
  {
    title: '期间下单金额(元)',
    dataIndex: 'qujianxiaofeimoney',
  
    ellipsis: true,
  },

];

const data = [
  {
    key: '1',
    name: 'John Brown',
    age: 32,
    address: 'New York No. 1 Lake Park, New York No. 1 Lake Park',
    tags: ['nice', 'developer'],
  },
  {
    key: '2',
    name: 'Jim Green',
    age: 42,
    address: 'London No. 2 Lake Park, London No. 2 Lake Park',
    tags: ['loser'],
  },
  {
    key: '3',
    name: 'Joe Black',
    age: 32,
    address: 'Sidney No. 1 Lake Park, Sidney No. 1 Lake Park',
    tags: ['cool', 'teacher'],
  },
    
  
];
    import JInput from '@/components/jeecg/JInput.vue'
      import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
import { deleteAction, getAction, putAction, postAction, downFile, getFileAccessHttpUrl } from '@/api/manage'
  export default {
    name: "addUsertoDiscount",
    data () {
      return {
		   dateFormat: 'YYYY-MM-DD',
		  companyCode:'',
		  companyName:'',
        realName:'',
 starttime:'',
        endtime:'',
            discountId:'',     //折扣的id
             /* 分页参数 */
		 pagination: {},	 
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      ids:[],
       /* table选中keys*/
      selectedRowKeys: [],
       /* table选中record*/
        selectionRows: [],
         data,
      columns,
        title:"操作",
        visible: false,
        xianshi:false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
        },
        url: {  list: "/BackCust/getBackCustList",
          add: "/Discount/addUsertoDiscount",
          edit: "/Discount/addUsertoDiscount",
		  
        },
      }
    },
    created() {
     //this.searchQuery();
      this.getpeopleList();
       
    },
    methods: {
		getQueryParams(){
		  //高级查询器
		  let sqp = {}
		  if(this.superQueryParams){
		    sqp['superQueryParams']=encodeURI(this.superQueryParams)
		    sqp['superQueryMatchType'] = this.superQueryMatchType
		  }
		  var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
		
		  param.field = this.getQueryField();
		  param.pageNo = this.ipagination.current;
		  param.pageSize = this.ipagination.pageSize;
		  delete param.birthdayRange; //范围参数不传递后台
		  return filterObj(param);
		},
		
		
     onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
   
      this.selectionRows = selectionRows;
        for (var i=0;i<this.selectionRows.length;i++)
         { 
              this.ids.push(this.selectionRows[i].id);
              console.log("看一看能不能成功"+this.ids[i]);
         }
    },
     handleTableChange(pagination, filters, sorter) {
      console.log(pagination);
      const pager = { ...this.pagination };
      pager.current = pagination.current;
      this.pagination = pager;
      // this.fetch({
      //   results: pagination.pageSize,
      //   page: pagination.current,
      //   sortField: sorter.field,
      //   sortOrder: sorter.order,
      //   ...filters,
      // });
	  this.fetch(this.pagination.current);
    },
     fetch(current){
		 this.ipagination.current= current;
		 this. getpeopleList();
	 },
     getpeopleList(){
          getAction(this.url.list,{
            realName:this.realName,
            starttime:this.starttime,
            endtime:this.endtime,
			companyName:this.companyName,
			companyCode:this.companyCode,
			pageSize:this.ipagination.pageSize,
			pageNo:this.ipagination.current,
			
          }).then((res)=>{
              if(res.success){
                  this.data = res.result.records;
                this.ipagination.total = res.result.total;
				 // this.ipagination.current = res.result.pages;
				 // this.ipagination.pageSize = res.result.size;
              }else{
                this.$message.warning(res.message);
              }
            })
     },

      add () {
        this.edit({});
      },
      edit (record) {
        this.discountId=record;
        console.log("输出看看折扣id嘛"+this.discountId);
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'name','keyWord','sex','age','email','content'))
		      //时间格式化
          this.form.setFieldsValue({punchTime:this.model.punchTime?moment(this.model.punchTime,'YYYY-MM-DD HH:mm:ss'):null})
          this.form.setFieldsValue({birthday:this.model.birthday?moment(this.model.birthday):null})
        });
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.punchTime = formData.punchTime?formData.punchTime.format('YYYY-MM-DD HH:mm:ss'):null;
            formData.birthday = formData.birthday?formData.birthday.format():null;
             formData['ids']=this.ids;
             formData['discountId']=this.discountId;
           httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
                  this.ids=[];
                   this.selectedRowKeys=[];
                     this.selectionRows=[];
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
			  this.getpeopleList()
              //that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>